//
//  BaseTabBarController.m
//  01-UIViewHomeWork
//
//  Created by dllo on 16/7/22.
//  Copyright © 2016年 QC.L. All rights reserved.
//

#import "BaseTabBarController.h"
#import "HomeViewController.h"
#import "FindViewController.h"
#import "MineViewController.h"
#import "MessageViewController.h"
#import "OtherTabBar.h"

@interface BaseTabBarController ()<OtherTabBarDelegate>

@end

@implementation BaseTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatTabBar];
}
- (void)creatTabBar {
    HomeViewController *homeVC = [[HomeViewController alloc] init];
    MessageViewController *messagerVC = [[MessageViewController alloc] init];
    FindViewController *findVC = [[FindViewController alloc] init];
    MineViewController *mineVC = [[MineViewController alloc] init];
    [self addChildVC:homeVC image:@"tab_首页_dark" seleImage:@"tab_首页_pressed"];
    [self addChildVC:findVC image:@"tab_社区_dark" seleImage:@"tab_社区_pressed"];
    [self addChildVC:messagerVC image:@"tab_分类_dark" seleImage:@"tab_分类_pressed"];
    [self addChildVC:mineVC image:@"我1" seleImage:@"我"];
    OtherTabBar *tabBar = [[OtherTabBar alloc] init];
    tabBar.delegate = self;
    // KVC：如果要修系统的某些属性，但被设为readOnly，就是用KVC，即setValue：forKey：。
    [self setValue:tabBar forKey:@"tabBar"];
}
/**
 *  添加一个子控制器
 *
 *  @param childVc       子控制器
 *  @param title         标题
 *  @param image         图片
 *  @param selectedImage 选中的图片
 */

- (void)addChildVC:(UIViewController *)childVC image:(NSString *)image seleImage:(NSString *)seleImage {
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVC];
    childVC.tabBarItem.image = [UIImage imageNamed:image];
    childVC.tabBarItem.selectedImage = [[UIImage imageNamed:seleImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSMutableDictionary *dicOne = [NSMutableDictionary dictionary];
    dicOne[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.61 green:0.61 blue:0.61 alpha:1.00];
    NSMutableDictionary *dicTwo = [NSMutableDictionary dictionary];
    dicTwo[NSForegroundColorAttributeName] = [UIColor colorWithRed:0.05 green:0.58 blue:0.18 alpha:1.00];
    [childVC.tabBarItem setTitleTextAttributes:dicOne forState:UIControlStateNormal];
    [childVC.tabBarItem setTitleTextAttributes:dicTwo forState:UIControlStateSelected];
    [self addChildViewController:nav];
    
}
/**
 *  按钮点击
 */
- (void)tabBarDidClickPlusButton:(OtherTabBar *)tabBar
{
    UIViewController *vc = [[UIViewController alloc] init];
    [self presentViewController:vc animated:YES completion:nil];
}


@end
